package com.yue.rpc.loadbalance;

import com.yue.rpc.remoting.dto.RpcRequest;
import com.yue.rpc.utils.CollectionUtil;

import java.util.List;

/**
 * @Author zhangqiyue
 * @Description
 * @Date 2023/3/4 16:00
 */
public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceUrlList, RpcRequest rpcRequest) {
        if (CollectionUtil.isEmpty(serviceUrlList)) {
            return null;
        }
        if (serviceUrlList.size() == 1) {
            return serviceUrlList.get(0);
        }
        return doSelect(serviceUrlList, rpcRequest);
    }

    protected abstract String doSelect(List<String> serviceUrlList, RpcRequest rpcRequest);
}
